package com.zh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.common.BaseResponse;
import com.zh.common.ErrorCode;
import com.zh.common.ResultUtils;
import com.zh.domain.dto.requirement.AddRequirementCommentRequest;
import com.zh.domain.dto.requirement.PageReqCommentRequest;
import com.zh.domain.dto.task.AddTaskCommentRequest;
import com.zh.domain.dto.task.PageTaskCommentRequest;
import com.zh.domain.vo.requirement.RequirementCommentVo;
import com.zh.domain.vo.task.TaskCommentVo;
import com.zh.exception.ThrowUtils;
import com.zh.service.ReqCommentsService;
import com.zh.service.TaskCommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "RequirementCommentsController", value = "需求评论控制器")
@RestController
@RequestMapping("/requirement-comment")
public class RequirementCommentsController {
    @Resource
    private ReqCommentsService reqCommentsService;

    @PostMapping
    @ApiOperation(value = "addRequirementComment", notes = "添加任务评论")
    public BaseResponse<Boolean> addRequirementComment(@RequestBody AddRequirementCommentRequest addTaskCommentRequest) {
        ThrowUtils.throwIf(null == addTaskCommentRequest, ErrorCode.PARAMS_ERROR);
        Boolean result = reqCommentsService.addReqComment(addTaskCommentRequest);
        return ResultUtils.success(result);
    }

    @PostMapping("/page")
    @ApiOperation(value = "pageRequirementComment", notes = "分页查询任务评论")
    public BaseResponse<Page<RequirementCommentVo>> pageRequirementComment(@RequestBody PageReqCommentRequest pageReqCommentRequest) {
        ThrowUtils.throwIf(null == pageReqCommentRequest, ErrorCode.PARAMS_ERROR);
        Page<RequirementCommentVo> result = reqCommentsService.pageReqComment(pageReqCommentRequest);
        return ResultUtils.success(result);
    }

    @DeleteMapping
    @ApiOperation(value = "deleteRequirementComment", notes = "删除需求评论")
    public BaseResponse<Boolean> deleteRequirementComment(Integer id) {
        boolean success = reqCommentsService.removeById(id);
        return ResultUtils.success(success);
    }
}
